<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form divClass" v-if="headerShow">
        <a-form size="small" :model="pageData.queryData" layout="inline">
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="发往单位名称">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.setCompanyName"
                allow-clear
              />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="申请单号">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.pickCode"
                allow-clear
              />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="物料编号">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.materialCode"
                allow-clear
              />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="物料名称">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.materialName"
                allow-clear
              />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="批次">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.batchNo"
                allow-clear
              />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="流转卡号">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.circulatCard"
                allow-clear
              />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="出库单号">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.outStockCode"
                allow-clear
              />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="出库类型">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.outStockType"
                allow-clear
              />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item :label-col-flex="pageData.labelColFlex1" label="批色配方单号">
              <a-input
                @press-enter="selectHandler"
                class="bacClass"
                v-model="pageData.queryData.batchcolorFormulaCode"
                allow-clear
              />
            </a-form-item>
          </a-col>
        </a-form>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
      <div class="my-tool-bar">
        <Toolbar
          :items="['查询', '新增', '删除']"
          @add="addHandler"
          @del="deleteHandler"
          @select="selectHandler"
        >
        </Toolbar>
      </div>
    </template>
    <template #pageTabel>
      <AgGridVuesCopys
        :rowHeight="33"
        :headerHeight="33"
        rowSelection="multiple"
        @grid-ready="gridReady"
        style="height: 100%"
        :defaultColDef="defaultColDef"
        class="ag-theme-alpine"
        :rowData="table.dataList"
        :columnDefs="tc"
        :localeText="localeText1"
        :suppressRowClickSelection="true"
      ></AgGridVuesCopys>
    </template>

    <paginationCopys
      :page-size="pagination.pageSize"
      :current="pagination.page"
      :total="pagination.total"
      show-total
      show-jumper
      show-page-size
      @change="nextDoRefreshPage"
      @page-size-change="nextDoRefreshSize"
      style="justify-content: center"
    />

    <a-drawer
      placement="bottom"
      :drawer-style="{ zIndex: 9999 }"
      :mask-closable="false"
      height="90%"
      :visible="pageData.showAdd"
      unmountOnClose
      @ok="sideOk"
      @cancel="pageData.showAdd = false"
      cancel-text="关闭"
      ok-text="保存"
    >
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div>
        <a-form ref="formRef" :model="dataForm" layout="horizontal">
          <a-row class="grid-demo" :gutter="24">
            <a-col :span="6">
              <a-form-item
                label="公司"
                :label-col-flex="pageData.labelColFlex"
                field="firmId"
                :rules="[{ required: true, message: '公司必填' }]"
              >
                <a-cascader
                  v-model="dataForm.firmId"
                  :options="dataForm.firmGroupList"
                  allow-clear
                  ref="casOb"
                  @change="companyChange"
                  class="bacClass"
                  popup-container="html"
                />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="仓库名称"
                field="warehouseName"
                :validate-trigger="['change', 'blur']"
              >
                <a-select popup-container="html"  v-model="dataForm.warehouseName" allow-clear class="bacClass">
                  <a-option v-for="item in dataForm.warehouseList" :value="item.id">
                    {{ item.warehouseName }}
                  </a-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="出库单号"
                field="outStockCode"
                :rules="[{ required: true, message: '出库单号必填' }]"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.outStockCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="出库类型"
                field="outStockType"
                :rules="[{ required: true, message: '出库单号必填' }]"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.outStockType" />
              </a-form-item>
            </a-col>

            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="发往单位编号"
                field="setCompanyCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.setCompanyCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="发往单位名称"
                field="setCompanyName"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.setCompanyName" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="领料人"
                field="pickPerson"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.pickPerson" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="机台"
                field="machine"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.machine" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="订单号"
                field="orderCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.orderCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="配方单号"
                field="batchcolorFormulaCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.batchcolorFormulaCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="流转卡号"
                field="circulatCard"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.circulatCard" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="班组"
                field="team"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.team" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="客户名称"
                field="customName"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.customName" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="作业性质"
                field="workNature"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.workNature" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="审核人"
                field="auditPerson"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.auditPerson" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="申请单号"
                field="pickCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.pickCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="条形码"
                field="barCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.barCode" />
              </a-form-item>
            </a-col>
            <a-col :span="24">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="备注"
                field="remark"
                :validate-trigger="['change', 'blur']"
              >
                <a-textarea class="bacClass" v-model="dataForm.remark" />
              </a-form-item>
            </a-col>
            <!-- <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="仓库编码"
                field="warehouseCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.warehouseCode" />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item
                :label-col-flex="pageData.labelColFlex"
                label="入库条码"
                field="inStockBarCode"
                :validate-trigger="['change', 'blur']"
              >
                <a-input class="bacClass" v-model="dataForm.inStockBarCode" />
              </a-form-item>
            </a-col> -->
          </a-row>
          <a-row class="grid-demo" :gutter="24">
            <el-table
              :data="[{}]"
              style="width: 100%"
              :header-cell-style="{ color: '#696969', background: '#f5f7fa' }"
              tooltip-effect="dark"
            >
              <el-table-column prop="" label="物料编号">
                <a-input v-model="dataForm.formulaPickDetail[0].materialCode" />
              </el-table-column>
              <el-table-column prop="" label="物料名称">
                <a-input v-model="dataForm.formulaPickDetail[0].materialName" />
              </el-table-column>
              <el-table-column prop="" label="规格">
                <a-input v-model="dataForm.formulaPickDetail[0].spec" />
              </el-table-column>
              <el-table-column prop="" label="单位">
                <a-input v-model="dataForm.formulaPickDetail[0].unit" />
              </el-table-column>
              <el-table-column prop="" label="库位">
                <a-input v-model="dataForm.formulaPickDetail[0].warehouseLocation" />
              </el-table-column>
              <el-table-column prop="" label="批次">
                <a-input v-model="dataForm.formulaPickDetail[0].batchNo" />
              </el-table-column>
              <el-table-column prop="" label="件数">
                <a-input-number v-model="dataForm.formulaPickDetail[0].pieceNum" />
              </el-table-column>
              <el-table-column prop="" label="数量">
                <a-input-number v-model="dataForm.formulaPickDetail[0].pickNum" />
              </el-table-column>
              <el-table-column prop="" label="公司">
                <a-input v-model="dataForm.formulaPickDetail[0].companyName" />
              </el-table-column>
              <el-table-column prop="" label="进口类别">
                <a-input v-model="dataForm.formulaPickDetail[0].importType" />
              </el-table-column>
              <el-table-column prop="" label="放置位置">
                <a-input v-model="dataForm.formulaPickDetail[0].placeLocation" />
              </el-table-column>
              <el-table-column prop="" label="备注">
                <a-input v-model="dataForm.formulaPickDetail[0].remark" />
              </el-table-column>
            </el-table>
          </a-row>
        </a-form>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>

<script lang="ts">
  import { post, get } from '@/api/http'
  import { useTable, usePagination, useTableColumn } from '@/hooks/table'

  import { ref, reactive, onMounted } from 'vue'
  import Toolbar from '@/components/Toolbar.vue'
  import { Message, Modal } from '@arco-design/web-vue'
  import { FormInstance } from '@arco-design/web-vue/es/form'
  import 'ag-grid-community/styles/ag-grid.css'
  import 'ag-grid-community/styles/ag-theme-alpine.css'
  import { localeText } from '@/api/aggridZw'
  
  import WHService from '@/service/wh'
  interface paramData {
    id: any
    outStockCode: string | undefined //出库单号
    warehouseCode: string | undefined //仓库编号
    circulatCard: string | undefined //流转卡号
    setCompanyName: string | undefined //发往单位编号
    setCompanyCode: string | undefined //发往单位名称
    pickPerson: string | undefined //领料人
    machine: string | undefined //机台
    outStockType: string | undefined //出库类型
    orderCode: string | undefined //订单号
    batchcolorFormulaCode: string | undefined //批色配方单号
    team: string | undefined //班组
    customName: string | undefined //客户名称
    auditPerson: string | undefined //审核人
    workNature: string | undefined //作业性质
    inStockBarCode: string | undefined //入库条码
    pickCode: string | undefined //申请单号
    barCode: string | undefined //条形码
    remark: string | undefined //备注
    formulaPickDetail: any
    firmId: any
    firmGroupList: any
    warehouseName: any
    warehouseList: any
  }

  export default {
    //配方领料
    name: 'RecipePicking',
    setup() {
      //隐藏显示头部
      const headerShow = ref<boolean>(true)
      const pageData = reactive<{
        showAdd: boolean
        sideTitle: string
        dropDownData: any
        pageLoading: boolean
        theight: number
        rHeight: number | undefined
        labelColFlex: string
        queryData: any
        labelColFlex1: string
        departmentTree: any
      }>({
        showAdd: false,
        sideTitle: '新增配方领料',
        dropDownData: '',
        pageLoading: false,
        theight: 0,
        rHeight: 0,
        labelColFlex: '120px',
        queryData: {
          pickCode: '',
          deleteState: 0,
          setCompanyName: '',
          materialCode: '',
          materialName: '',
          batchNo: '',
          circulatCard: '',
          outStockCode: '',
          outStockType: '',
          batchcolorFormulaCode: '',
        },
        labelColFlex1: '100px',
        departmentTree: [],
      })
      const dataForm = reactive<paramData>({
        id: null,
        outStockCode: '', //出库单号
        warehouseCode: '', //仓库编号
        circulatCard: '', //流转卡号
        setCompanyName: '', //发往单位编号
        setCompanyCode: '', //发往单位名称
        pickPerson: '', //领料人
        machine: '', //机台
        outStockType: '', //出库类型
        orderCode: '', //订单号
        batchcolorFormulaCode: '', //批色配方单号
        team: '', //班组
        customName: '', //客户名称
        auditPerson: '', //审核人
        workNature: '', //作业性质
        inStockBarCode: '', //入库条码
        pickCode: '', //申请单号
        barCode: '', //条形码
        remark: '', //备注
        formulaPickDetail: [],
        firmId: '',
        firmGroupList: [],
        warehouseName: '',
        warehouseList: [],
      })
      //查询列表
      onMounted(() => {
        selectHandler()
      })
      //   // 获取公司列表
      const getFirmGroup = () => {
        post({
          url: 'org/baCompany/getTreeCompanyByUser',
          data: {},
        }).then(({ code, data }) => {
          if (code === 200) {
            dataForm.firmGroupList = data
          }
        })
      }
      const whService = new WHService()
      const companyChange = () => {
        whService.getWarhouseListByFirmId(dataForm.firmId, '化工仓')
        dataForm.warehouseList = whService.whList.value
      }
      //切换分页
      const nextDoRefreshPage = (val: any) => {
        pagination.page = val
        doRefresh()
      }
      const nextDoRefreshSize = (val: any) => {
        pagination.pageSize = val
        doRefresh()
      }
      const pagination = usePagination(doRefresh)
      const table = useTable()
      function doRefresh() {
        pageData.pageLoading = true
        pageData.queryData.page = pagination.page
        pageData.queryData.size = pagination.pageSize
        post({
          url: 'dwQms/FormulaPick/getPage',
          data: pageData.queryData,
        })
          .then(({ data, code }: any) => {
            if (code === 200) {
              table.handleSuccess(data.list)
              pagination.setTotalSize(data.total)
              gridOption.value.setRowData(data.list)
            }
          })
          .catch(console.log)
          .finally(() => {
            pageData.pageLoading = false
          })
      }
      //查询
      const selectHandler = () => {
        pagination.page = 1
        doRefresh()
      }
      //------新增、修改页面开始------
      const addHandler = () => {
        getFirmGroup()
        getBmGroup()
        for (var key in dataForm) {
          if (key === 'id') {
            dataForm[key] = null
          } else if (key === 'formulaPickDetail') {
            dataForm[key] = [
              {
                materialCode: '', //物料编号
                materialName: '', //物料名称
                spec: '', //规格
                unit: '', //单位
                warehouseLocation: '', //库位
                batchNo: '', //批次
                pieceNum: 0, //件数
                pickNum: 0, //数量
                companyName: '', //公司
                importType: '', //进口类别
                placeLocation: '', //放置位置
                remark: '', //备注
              },
            ]
          } else if (Array.isArray(dataForm[key])) {
            dataForm[key] = []
          } else {
            dataForm[key] = ''
          }
        }
        pageData.showAdd = true
        pageData.sideTitle = '新增配方领料'
      }
      const editHandler = (record: paramData) => {
        dataForm.formulaPickDetail = [
          {
            materialCode: '', //物料编号
            materialName: '', //物料名称
            spec: '', //规格
            unit: '', //单位
            warehouseLocation: '', //库位
            batchNo: '', //批次
            pieceNum: 0, //件数
            pickNum: 0, //数量
            companyName: '', //公司
            importType: '', //进口类别
            placeLocation: '', //放置位置
            remark: '', //备注
          },
        ]
        getBmGroup()
        for (var key in record) {
          dataForm[key] = record[key]
        }
        post({
          url: 'dwQms/FormulaPickDetail/getList',
          data: {
            formulaPickId: record.id,
          },
        }).then(({ data, code }: any) => {
          if (code === 200) {
            dataForm.formulaPickDetail = data
            if (data[0].pieceNum) {
              dataForm.formulaPickDetail[0].pieceNum = Number(data[0].pieceNum)
            }
            if (data[0].pickNum) {
              dataForm.formulaPickDetail[0].pickNum = Number(data[0].pickNum)
            }
          }
        })
        pageData.sideTitle = '修改配方领料'
        pageData.showAdd = true
      }

      const formRef = ref<FormInstance>()
      const sideOk = () => {
        formRef.value?.validate().then((err) => {
          if (!err) {
            if (pageData.sideTitle === '新增配方领料') {
              post({
                url: 'dwQms/FormulaPick/insertList',
                data: dataForm,
              }).then((res: any) => {
                if (res.code === 200) {
                  formRef.value?.resetFields()

                  pageData.showAdd = false

                  Message.success({
                    content: '新增成功',
                    duration: 5000,
                  })
                  selectHandler()
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
              })
            } else {
              post({
                url: 'dwQms/FormulaPick/updateList',
                data: dataForm,
              }).then((res: any) => {
                if (res.code === 200) {
                  formRef.value?.resetFields()
                  pageData.showAdd = false

                  Message.success({
                    content: '修改成功',
                    duration: 5000,
                  })
                  selectHandler()
                } else {
                  Message.error({
                    content: res.message,
                    duration: 5000,
                  })
                }
              })
            }
          }
        })
      }
      //------新增、修改页面结束------
      //------删除方法开始------
      const deleteHandler = () => {
        if (gridOption.value.getSelectedRows().length === 0) {
          return
        }
        Modal.confirm({
          title: '系统提示',
          content: '确认删除选中的数据?',
          onOk() {
            post({
              url: 'dwQms/FormulaPick/delete',
              data: gridOption.value.getSelectedRows().map((o: any) => {
                return o.id
              }),
            }).then(({ code, data }: any) => {
              if (code === 200) {
                Message.success({
                  content: '删除成功',
                  duration: 5000,
                })

                pagination.page = 1
                selectHandler()
              } else {
                Message.error({
                  content: '删除失败',
                  duration: 5000,
                })
              }
            })
          },
        })
      }
      //------删除方法结束------

      // 表格准备事件
      const tableColumns = useTableColumn([
        {
          title: '序号',
          key: 'id',
          dataIndex: 'id',
          width: '150px',
        },
        {
          title: '出库编号',
          key: 'outStockCode',
          dataIndex: 'outStockCode',
        },
        {
          title: '出库类型',
          key: 'outStockType',
          dataIndex: 'outStockType',
        },
        {
          title: '发往单位编号',
          key: 'setCompanyCode',
          dataIndex: 'setCompanyCode',
        },
        {
          title: '发往单位名称',
          key: 'setCompanyName',
          dataIndex: 'setCompanyName',
        },
        {
          title: '目标仓库',
          key: 'warehouseName',
          dataIndex: 'warehouseName',
        },
        // {
        //   title: '物料编号',
        //   key: 'materialCode',
        //   dataIndex: 'materialCode',
        // },
        // {
        //   title: '物料名称',
        //   key: 'materialName',
        //   dataIndex: 'materialName',
        // },
        // {
        //   title: '规格',
        //   key: 'spec',
        //   dataIndex: 'spec',
        // },

        // {
        //   title: '数量',
        //   key: 'pickNum',
        //   dataIndex: 'pickNum',
        // },
        {
          title: '流转卡号',
          key: 'circulatCard',
          dataIndex: 'circulatCard',
        },
        {
          title: '配方单号',
          key: 'batchcolorFormulaCode',
          dataIndex: 'batchcolorFormulaCode',
        },

        {
          title: '订单号',
          key: 'orderCode',
          dataIndex: 'orderCode',
        },
        {
          title: '审核人',
          key: 'auditPerson',
          dataIndex: 'auditPerson',
        },
        {
          title: '修改人',
          key: 'updateName',
          dataIndex: 'updateName',
        },

        {
          title: '修改日期',
          key: 'updateTime',
          dataIndex: 'updateTime',
        },
        {
          title: '备注',
          key: 'remark',
          dataIndex: 'remark',
        },

        {
          title: '创建人',
          key: 'createName',
          dataIndex: 'createName',
        },
        {
          title: '创建时间',
          key: 'createTime',
          dataIndex: 'createTime',
        },

        {
          title: '操作',
          key: 'id',
          dataIndex: 'id',
          slotName: 'act',
          width: 150,
          fixed: 'right',
        },
      ])
      const gridOption = ref()
      const gridReady = (params: any) => {
        gridOption.value = params.api
      }
      const defaultColDef = {
        sortable: true,
        resizable: true,
        filter: true,
        // flex: 1
      }
      let tc: any[] = tableColumns.map((o) => {
        let obj = {
          headerName: o.title,
          field: o.key,
          pinned: o['fixed'],
          width: o.width,
          children: o.children,
          cellRenderer: o.cellRenderer,
        }
        if (o.slotName === 'act') {
          obj['resizable'] = false
          obj['filter'] = false
          obj['sortable'] = false
          obj['lockPosition'] = o.fixed
          obj['cellRenderer'] = {
            template: `<el-button style="color:#165dff;" link @click="a">修改</el-button>`,
            setup(props: any) {
              const a = () => {
                editHandler(props.params.data)
              }
              return {
                a,
              }
            },
          }
        }
        return obj
      })
      let a = [
        {
          showRowGroup: 'hide_def',
          headerName: '',
          checkboxSelection: true,
          headerCheckboxSelection: true,
          pinned: 'left',
          width: 50,
          resizable: false,
          filter: false,
          sortable: false,
          minWidth: 50,
          maxWidth: 50,
          lockPosition: 'left',
        },
      ]
      tc = a.concat(tc)
      const localeText1: any = ref(localeText)

      // 获取部门列表
      const getBmGroup = () => {
        post({
          url: 'org/baCompany/getDepartmentTree?companyId=' + 12,
        }).then((result) => {
          if (result.code === 200) {
            pageData.departmentTree = result.data
          }
        })
      }
      const setAudit = () => {
        if (gridOption.value.getSelectedRows().length !== 1) {
          Message.error({
            content: '请只选择一条数据进行审核！',
            duration: 5000,
          })
          return
        }
        Modal.confirm({
          title: '系统提示',
          content: '确认审核选中的数据?',
          onOk() {
            var obj: any = {
              id: gridOption.value.getSelectedRows()[0].id,
              auditState: 1,
            }
            post({
              url: 'dwQms/BatchcolorFormula/setAudit',
              data: [obj],
            }).then(({ code, data }: any) => {
              if (code === 200) {
                Message.success({
                  content: '操作成功',
                  duration: 5000,
                })

                pagination.page = 1
                selectHandler()
              } else {
                Message.error({
                  content: '操作失败',
                  duration: 5000,
                })
              }
            })
          },
        })
      }

      return {
        deleteHandler,
        sideOk,
        formRef,
        dataForm,
        addHandler,
        pagination,
        table,
        pageData,
        editHandler,
        selectHandler,
        headerShow,
        nextDoRefreshPage,
        nextDoRefreshSize,
        defaultColDef,
        localeText1,
        tc,
        gridReady,
        gridOption,
        getBmGroup,
        setAudit,
        companyChange,
        getFirmGroup,
      }
    },
    components: { Toolbar,  },
  }
</script>
<style scoped lang="less">
  :deep(.ag-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-header-cell) {
    border-right: 1px solid #dde2eb;
  }

  :deep(.ag-cell-value) {
    user-select: initial;
    -moz-user-select: text;
    -ms-user-select: text;
    -webkit-user-select: text;
  }
</style>
